module executor.authorize.AuthorizeExecutor;

import msgtrans;
import message.Constants;
import cache.UserStatusManager;
import hunt.logging;
import google.protobuf;
import message.MsgDefine;
import cache.ChatIdMap;
import client.GateServerClient;
import std.array;
import std.conv : to;

@TransportServer(MsgServerName)
class AuthorizeExecutor : AbstractExecutor!(AuthorizeExecutor) {

  @MessageId(MESSAGE.CMD_AUTHORIZE_REQ)
  void authorize(TransportContext ctx, MessageBuffer buffer)
  {
    UserStatus userStatus = new UserStatus;
    buffer.data.fromProtobuf!UserStatus(userStatus);
    logInfo("update user %s status %d",userStatus.userId, true);
    //string userId = cast(string)buffer.data;
    //UserStatusManager.getInstance().setUserStatus(userStatus.userId,userStatus.src,false);
    try
    {
      UserStatusManager.getInstance().setUserStatus(userStatus.userId,userStatus.src,true);
    }catch(Throwable e)
    {
      logErrorf("error :%s",e);
    }


  }
}

